package lupos;

import java.util.List;
import java.util.ArrayList;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/** 
 * The role of this class is to parse 'Layer' elements of
 * FrameNet 1.3 annotation files. The format of these
 * elements is as follows:
 * 
 *   layer @ID @name (@rank)
 *     > labels
 *         > label*
 * 
 * The ID attribute is ignored. 
 */

public class Layer {

	public String name;
	public String rank = "";
	public List<Label> labels = new ArrayList<Label>();
	
	public Layer(Element e) {
		name = e.getAttribute("name");
		if (e.hasAttribute("rank")) rank = e.getAttribute("rank");
		NodeList ns = e.getChildNodes();
		for (int i=0;i<ns.getLength();i++) {
			Node n = ns.item(i);
			String s = n.getNodeName();
			if (s.equals("labels")) {
				NodeList ps = ((Element) n).getChildNodes();
				for (int j=0;j<ps.getLength();j++) {
					Node p = ps.item(j);
					if (p.getNodeName().equals("label")) {
						labels.add(new Label((Element) p));
					}
				}
			}
		}
	}
	
}
